%script to read the AE index (minute) yearly files and
% put thed ata into a single array for years 1995-2012




time_array_min = (datenum(1995,1,1,0,0,30): (1/(24*60)): datenum(2012,12,31,23,59,30))';
 time_array_min = (datenum(1995,1,1,0,0:9468000-1,30));

time_array_min = round(time_array_min*1000000)/1000000;

a = length(time_array_min);
ae_min_1995_2012 = nan([1,a]);

%%
for years = 1995:2011,

fname=  ['/Users/manojnair/projects/ae_index/ae_' sprintf('%d',years) '_minute.txt'];
[data,fday] = read_wdc_ae_index(fname);

fday = round(fday*1000000)/1000000;


[b,ia,ib] = intersect(time_array_min, fday);


if length(b) == length(data),
ae_min_1995_2012(ia) = data;

fprintf('Completed %s \n',fname);
else
    fprintf('Error %s \n',fname);
end;


end;

% special treatment for year 1999

fname=  ['/Users/manojnair/projects/ae_index/ae_1999_minute.txt'];
[data,fday] = read_wdc_ae_index(fname);

ae_min_1995_2012(2103841:2103841+length(data) - 1) = data;

% read the 2012 data from WDC Kyoto. This data are in IAGA column format.
% It was "awked" into out.txt

data = load('/Users/manojnair/projects/ae_index/out.txt');
[b,ia] = intersect(time_array_min, datenum(2012,1,1,0,0,30))
ae_min_1995_2012(8940961:8940961+length(data) - 1) = data;

% read 2011 (there is an issue with the fday returend for 2011. So add it
% manually

fname=  ['/Users/manojnair/projects/ae_index/ae_2011_minute.txt'];
[data,fday] = read_wdc_ae_index(fname);
[b,ia] = intersect(time_array_min, datenum(2011,1,1,0,0,30))
ae_min_1995_2012(8415361:8415361+length(data) - 1) = data;

% save data

save /Users/manojnair/projects/ae_index/ae_min_1995_2012 ae_min_1995_2012;
